514B - Han Solo and Lazer Gun - CodeForces Solution


brute force data structures geometry implementation math *1400

Please click on ads to support us..

Python Code:

def solve():
    n, x0, y0 = map(int, input().split())
    k = set()
    for i in range(n):
        x, y = map(int, input().split())
        if x == x0:
            k.add(1010101010101010)
        else:
            k.add((y - y0) / (x - x0))
    print(len(k))
solve()

C++ Code:

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, x, y;
    scanf("%d %d %d", &n, &x, &y);
    map<pair<int, int>, int> m;
    for(int i = 0; i < n; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        a -= x;
        b -= y;
        int g = __gcd(a, b);
        a /= g;
        b /= g;
        if(b < 0){
            a = -a;
            b = -b;
        }
        m[{a, b}] = 1;
    }
    printf("%d\n", m.size());
    return 0;
}


Comments

Submit
0 Comments
More Questions

Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people